package cloud.lysky.java.on.concurrent.thread;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * @author luoly
 * @describe
 * @date 2023/2/27 17:43
 **/
public class JavaIsMultithreadingDemo {
    public static void main(String[] args) {
        // Java虚拟机线程系统的管理接口
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        // 不需要获取同步的monitor和synchronizer信息, 仅仅获取线程和线程堆栈信息
        ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);
        //遍历线程信息，仅打印线程ID和线程名称信息
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.println("[" + threadInfo.getThreadId() + "]" + threadInfo.getThreadName());
        }

        /**
         * [1]main
         * [2]Reference Handler
         * [3]Finalizer
         * [4]Signal Dispatcher
         * [5]Attach Listener
         * [21]Common-Cleaner
         * [22]Monitor Ctrl-Break
         * [23]Notification Thread
         */
    }
}
